class People: 
  # 类变量
  count = 0 
  # constructor 固定函数为 __init__
  def __init__(self, name, age):
    self.name = name
    self.age = age

  def sayHello(self):
    People.count += 1
    print('hello, my name is ' + self.name + ', I am ' + str(self.age) + ' years old, count is ' + str(People.count))

zhangsan = People('zhangsan', 18)
zhangsan.sayHello()

lisi = People('lisi', 20)
lisi.sayHello()
lisi.age = 21
print(lisi.age) # age: 21

# 继承
# 继承是面向对象编程的一个重要特性，它允许我们创建一个新的类，这个类可以继承一个或多个父类的属性和方法
class Student(People): 
  # 定义子类构造方法
  def __init__(self, name, age, height):
    super().__init__(name, age) # 调用父类构造方法 
    self.height = height
  
  # 重写父类方法
  def sayHello(self):
    print('hello, my name is ' + self.name + ', I am ' + str(self.age) + ' years old, my height is ' + str(self.height))

xiaoming = Student('xiaoming', 19, 180)
xiaoming.sayHello()
